/* 
 * File:   svg_path_curve.cpp
 * Author: Satan
 * 
 * Created on September 9, 2012, 9:07 PM
 */

#include "svgloader/svg_path_curve.h"

svg_path_instruction_curve::svg_path_instruction_curve(float ax, float ay, float bx, float by, float cx, float cy, float dx, float dy) 
{
    m_ax = ax;
    m_ay = ay;
    m_p1x = bx;
    m_p1y = by;
    m_p2x = cx;
    m_p2y = cy;
    m_bx = dx;
    m_by = dy;
}

svg_path_instruction_curve::svg_path_instruction_curve(const svg_path_instruction_curve& orig) 
{
}

svg_path_instruction_curve::~svg_path_instruction_curve() 
{
}

hfgl_point svg_path_instruction_curve::curves(float t)
{
    hfgl_point ret(0, 0);
    
    float var1 = 1.0 - t;
    float var2 = var1 * var1 * var1;
    float var3 = t * t * t;

    ret.x = var2*m_ax + 3.0*t*var1*var1*m_p1x + 3.0*t*t*var1*m_p2x + var3*m_bx;
    ret.y = var2*m_ay + 3.0*t*var1*var1*m_p1y + 3.0*t*t*var1*m_p2y + var3*m_by;

    return ret;
}

void svg_path_instruction_curve::getPoints(std::vector<hfgl_point>* surface, int step = 30)
{
    for (int i = 1; i <= step; i++)
        surface->push_back(curves(float(i)/float(step)));
}